package com.xiaohudie.JDBC;

import java.sql.*;
import java.util.ResourceBundle;

/**
 * @Author xiao hu die
 * @Date 2022/3/13 11:52
 * @Version 1.0
 */
public class TestJdbcResProperties {
 public static void main(String[] args) {
  ResourceBundle resourceBundle =ResourceBundle.getBundle("resources/db");
  String driver = resourceBundle.getString("driver");
  String url = resourceBundle.getString("url");
  String user = resourceBundle.getString("user");
  String password = resourceBundle.getString("password");
  Connection connection =null;
  Statement statement =null;
  ResultSet resultSet =null;
  /**注册驱动*/
  try {
   Class.forName(driver);
   /**获取连接*/
   connection = DriverManager.getConnection(url,user,password);
   /**获取数据库操作对象*/
   statement = connection.createStatement();
   /**获取sql语句*/
  String InsertSql= "INSERT INTO user (id,name,phone) VALUES (9,'杜聚兵','13695478526')";
  /**执行sql*/
  int i = statement.executeUpdate(InsertSql);
   System.out.println("受影响的行数------》"+i);
  } catch (Exception e) {
   e.printStackTrace();
  }finally {
   if (resultSet!=null){
    try {
     resultSet.close();
    } catch (SQLException e) {
     e.printStackTrace();
    }
   }
   if (statement!=null){
    try {
     statement.close();
    } catch (SQLException e) {
     e.printStackTrace();
    }
   }
   if (connection!=null){
    try {
     connection.close();
    } catch (SQLException e) {
     e.printStackTrace();
    }
   }
  }

 }
}
